package com.xizi.atomic;

import java.util.concurrent.atomic.AtomicInteger;

class AtomicIntegerTest {
    private static AtomicInteger count = new AtomicInteger();
    //使用AtomicInteger之后，不需要对该方法加锁，也可以实现线程安全。

    public void increment() {
        count.incrementAndGet();
    }

    public int getCount() {
        return count.get();
    }

    public static void main(String[] args) {
        System.out.println(count.get());
        int andIncrement = count.getAndIncrement();
        count.compareAndSet(1, 1111);
        System.out.println(count.get());

    }
}
